package io.renren.modules.app.controller;
import io.renren.common.result.Result;
import io.renren.common.validator.ValidatorUtils;
import io.renren.common.validator.group.AddGroup;
import io.renren.common.validator.group.UpdateGroup;
import io.renren.modules.medical.entity.QuestionnaireSurveyEntity;
import io.renren.modules.medical.service.QuestionnaireSurveyService;
import io.renren.modules.medical.vo.weixinVo.ApiQuestionnaireListVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * @author Luo Sheng
 * @school YiBin university
 * @create 2023-05-22 17:03
 */



/**
 * 问卷调查接口
 */
@RestController
@RequestMapping("/app/questionnaire/survey")
@RequiredArgsConstructor
public class QuestionnaireSurveyApi {
    private final QuestionnaireSurveyService questionnaireSurveyService;


    /**
     * 添加问卷
     * @param questionnaireSurveyEntity
     * @return
     */
    @PostMapping("/save")
    public Result<String> save(@RequestBody QuestionnaireSurveyEntity questionnaireSurveyEntity){
        ValidatorUtils.validateEntity(questionnaireSurveyEntity, AddGroup.class);
        Long patientId = 6L;
        questionnaireSurveyEntity.setPatientInfoId(patientId);
        questionnaireSurveyService.save(questionnaireSurveyEntity);
        return Result.success(null);
    }

    /**
     * 获取问卷历史集合
     * @return
     */
    @GetMapping("/list")
    public Result<List<ApiQuestionnaireListVo>> list(){
        List<ApiQuestionnaireListVo> questionnaireList = questionnaireSurveyService.historyList(-1L);
        return Result.success(questionnaireList);
    }

    /**
     * 获取问卷详细信息
     * @param id
     * @return
     */
    @GetMapping("/info/{id}")
    public Result<QuestionnaireSurveyEntity> info(@PathVariable("id") Long id){
        QuestionnaireSurveyEntity questionInfo = questionnaireSurveyService.getById(id);
        return Result.success(questionInfo);
    }

    /**
     * 更新用户问卷
     * @return
     */
    @PostMapping("/update")
    public Result<String> update(@RequestBody QuestionnaireSurveyEntity questionnaireSurveyEntity) {
        ValidatorUtils.validateEntity(questionnaireSurveyEntity, UpdateGroup.class);
        questionnaireSurveyService.updateById(questionnaireSurveyEntity);
        return Result.success(null);
    }

}
